<template>
  <div>
    <h1>退款管理</h1>
 
    <el-table
      ref="multipleTable"
      tooltip-effect="drak"
      style="width: 100%"
      :data="list"
      border
			stripe
      @selection-change="handleSelectionChange"
    >
    <el-table-column label="购买者" prop="buyer" width="160">
    </el-table-column>
      <el-table-column label="餐厅" prop="shopName" width="160">
      </el-table-column>
      <el-table-column
        label="餐品"
        prop="name"
        width="100"
      ></el-table-column>
      <el-table-column
        label="价格"
        prop="money"
        width="100"
      ></el-table-column>
      <el-table-column
      label="数量"
      prop="num"
      width="100"
    ></el-table-column>
    <el-table-column
    label="购买餐品时间"
    prop="createTime"
    width="200"
  ></el-table-column>
  <el-table-column
  label="收货地址"
  prop="address"
  width="200"
></el-table-column>
  <el-table-column
  label="物流状态"
  prop="logisticsStatus"
  width="100"
></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
          @click="agree(scope.row.id)" 
          size="mini"
          v-if=" scope.row.logisticsStatus=='申请退款' "
          >退款确定</el-button>
          <el-button
          @click="reject(scope.row.id)" 
          size="mini"
          v-if=" scope.row.logisticsStatus=='申请退款' "
          >重新下单</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: "Reject",
  data() {
    const isNum = (rule, value, callback) => {
      const price = /^[0-9]*$/;
      if (!price.test(value)) {
        callback(new Error("金额只能为数字"));
      } else {
        callback();
      }
    };
    const isNum2 = (rule, value, callback) => {
      const num = /^[0-9]*$/;
      if (!num.test(value) || num > 0) {
        callback(new Error("数量必须大于0"));
      } else {
        callback();
      }
    };
    return {
      list: [],
      addForm: false,
      searchForm: {
        name: "",
        shopName: "",
      },
      multipleSelection:[],

      keyMap: {
        pid: "pid",
        id: "id",
      },
      searchInfo: false,
      payInfo: false,
      goods: {},
      formRules: {
        name: [
          {
            required: true,
            message: "请输入商品名称",
            trigger: "blur",
          },
        ],
        shopName: [
          {
            required: true,
            message: "请输入商店名称",
            trigger: "blur",
          },
        ],
        breakfast: [
          {
            required: true,
            message: "请输入商品早餐",
            trigger: "blur",
          },
        ],
        lunch: [
          {
            required: true,
            message: "请输入商品午餐",
            trigger: "blur",
          },
        ],
        dinner: [
          {
            required: true,
            message: "请输入商品晚餐",
            trigger: "blur",
          },
        ],
        money: [
          {
            required: true,
            message: "请输入商品价格",
            trigger: "blur",
          },
          {
            validator: isNum,
            message: "数量必须正整数",
            trigger: "blur",
          },
          {
            validator:  isNum2,
            message:"数量至于1件",
            trigger:"blur",
          }
        ],
        description: [
          { required: true, message: "请输入商品概要", trigger: "blur" },
        ],
     
      },
      commentDatas: [],
      info: {},
      buyInfo: false,
      infoRules: {
        num: [
          {
            required: true,
            message: "请输入购物数量",
            trigger: "blur",
          },
          {
            validator: isNum,
            message: "价格必须大于0",
            trigger: "blur",
          },
        ],
        address: [
          {
            required: true,
            message: "请输入收货地址",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    getList() {
      this.$axios
        .get("/goods/info/list", {
          params: {
            status: 1,
            reject: 1
          },
        })
        .then((res) => {
          this.list = res.data.data;
        });
    },
    agree(id){
      this.$axios.get("/goods/info/agree?id="+id).then((res)=>{
        this.getList();
        this.$message({
          showClose: true,
          message: res.data.data,
          type: "success"
        })
      })
    },
    reject(id){
      this.$axios.get("/good/info/reject1?id="+id).then((res)=>{
        this.getList();
        this.$message({
          showClose: true,
          message: res.data.data,
          type: "success"
        })
      })
    }
    
  
  },
 

  created() {
    this.getList();
  },
};
</script>

<style scoped>
.container h3 {
  margin-left: 50%;
  transform: translateX(-25%);
  margin-top: -20px;
}
.search_dialog {
  margin-left: 10% !important;
}
.has-colon {
  font-weight: 600;
}
.remark {
  margin-left: 50%;
  transform: translateX(-25%);
  color: #ccc;
  font-size: 25px;
}
.el-table {
  font-size: 18px;
}
div /deep/.el-dialog__title,
h3 {
  font-size: 22px;
}
.el-descriptions{
 font-size: 18px;
}
</style>